package com.wins.contact.domain;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@RooJavaBean
@RooToString
@RooEntity
public class Contact extends AbstractAuthenticatedEntity {

    private String name;


	public static List<Contact> findAllContacts() {
        return entityManager().createQuery("select o from Contact o where user_name = ?").setParameter(1, SecurityContextHolder.getContext().getAuthentication().getName()).getResultList();
    }

	public static List<Contact> findContactEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("select o from Contact o where user_name = ?").setParameter(1, SecurityContextHolder.getContext().getAuthentication().getName()).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
}
